//
//  FSWSegmentedButtonView.m
//  quhuolang_driver
//
//  Created by 曹欣欣 on 2018/3/1.
//  Copyright © 2018年 fusw. All rights reserved.
//

#import "FSWSegmentedButtonView.h"
@interface FSWSegmentedButtonView()
@property (weak, nonatomic) IBOutlet UIButton *pwdButton;
@property (weak, nonatomic) IBOutlet UIButton *codeButton;
@property (weak, nonatomic) IBOutlet UIView *pwdView;
@property (weak, nonatomic) IBOutlet UIView *codeView;
@property (nonatomic, copy) clickButtonBlock clickBlock;
@end

@implementation FSWSegmentedButtonView

- (IBAction)buttonAction:(UIButton *)sender {
    if (self.clickBlock) {
        self.clickBlock(sender.tag);
    }
    switch (sender.tag) {
        case 99:
            self.pwdView.backgroundColor = [UIColor colorWithHexString:@"FECB2F"];
            self.codeView.backgroundColor = [UIColor colorWithHexString:@"85B641"];
            break;
            
        default:
            self.pwdView.backgroundColor = [UIColor colorWithHexString:@"85B641"];
            self.codeView.backgroundColor = [UIColor colorWithHexString:@"FECB2F"];
            break;
    }
}
+ (void)show:(NSInteger)index andSuperView:(UIView*)superView addBlock:(clickButtonBlock)clickBlock{
    
    FSWSegmentedButtonView* emptyview = (FSWSegmentedButtonView*)[[NSBundle mainBundle] loadNibNamed:@"FSWSegmentedButtonView" owner:nil options:nil].firstObject;
    emptyview.frame = superView.bounds;
    [emptyview type:index addBlock:clickBlock];
    [superView insertSubview:emptyview atIndex:0]                                                                                                                                                                                                                                                                                                                                                                                                 ;
    [emptyview bringOneLevelUp];
}

#pragma mark - Private Method
- (void)type:(NSInteger)type addBlock:(clickButtonBlock)clickBlock{
    self.clickBlock = clickBlock;
    switch (type) {
        case 99:
            self.pwdView.backgroundColor = [UIColor colorWithHexString:@"FECB2F"];
            self.codeView.backgroundColor = [UIColor colorWithHexString:@"85B641"];
            break;
            
        default:
            self.pwdView.backgroundColor = [UIColor colorWithHexString:@"85B641"];
            self.codeView.backgroundColor = [UIColor colorWithHexString:@"FECB2F"];
            break;
    }
}
@end
